home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Workbench Add-On
/
Workbench Add-On - Volume 1.iso
/
Gfx
/
Edit
/
TSMorph
/
src
/
jpeg_ls
/
jwrmem.c
< prev
Wrap
C/C++ Source or Header
|
1994-10-30
|
4KB
|
142 lines
/*
* jwrmem.c
*
* Copyright (C) 1991, 1992, Thomas G. Lane.
* This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file.
*
* This file contains routines to write output images to memory - based on jwrppm.c
*
* These routines are invoked via the methods put_pixel_rows, put_color_map,
* and output_init/term.
*/
#include "jinclude.h"
#include <proto/exec.h>
extern UBYTE *r1,*g1,*b1;
/*
* Write the file header.
*/
static UBYTE *curr,*curg,*curb;
METHODDEF void
output_init (decompress_info_ptr cinfo)
{
/* Allocate the memory */
if (cinfo->quantize_colors) {
if (cinfo->output_file = (BPTR)AllocVec(((((ULONG)cinfo->image_width+15)>>4)<<4) * (ULONG)cinfo->image_height,NULL)) {
curr = (UBYTE *)cinfo->output_file;
}
else {
ERREXIT(cinfo->emethods, "Unable to allocate Memory"); // ????
}
}
else {
if (cinfo->output_file = (BPTR)AllocVec(((((ULONG)cinfo->image_width+15)>>4)<<4) * (ULONG)cinfo->image_height * (ULONG)3,NULL)) {
curr = (UBYTE *)cinfo->output_file;
curg = curr + (((cinfo->image_width+15)>>4)<<4) * cinfo->image_height;
curb = curg + (((cinfo->image_width+15)>>4)<<4) * cinfo->image_height;
}
else {
ERREXIT(cinfo->emethods, "Unable to allocate Memory"); // ????
}
}
}
/*
* Write some pixel data.
*/
METHODDEF void
put_color_rows (decompress_info_ptr cinfo, int num_rows,
JSAMPIMAGE pixel_data)
{
register JSAMPROW ptr0;
register JSAMPROW ptr1;
register JSAMPROW ptr2;
register long col;
long width = cinfo->image_width;
int row;
if (cinfo->quantize_colors) {
for (row = 0; row < num_rows; row++) {
ptr0 = pixel_data[0][row];
for (col = width; col > 0; col--) {
*curr = GETJSAMPLE(*ptr0);
curr++;
ptr0++;
}
curr += ((((cinfo->image_width+15)>>4)<<4) - cinfo->image_width);
}
}
else {
for (row = 0; row < num_rows; row++) {
ptr0 = pixel_data[0][row];
ptr1 = pixel_data[1][row];
ptr2 = pixel_data[2][row];
for (col = width; col > 0; col--) {
*curr = GETJSAMPLE(*ptr0);
curr++;
ptr0++;
*curg = GETJSAMPLE(*ptr1);
curg++;
ptr1++;
*curb = GETJSAMPLE(*ptr2);
curb++;
ptr2++;
}
curr += ((((cinfo->image_width+15)>>4)<<4) - cinfo->image_width);
curg += ((((cinfo->image_width+15)>>4)<<4) - cinfo->image_width);
curb += ((((cinfo->image_width+15)>>4)<<4) - cinfo->image_width);
}
}
}
METHODDEF void
put_color_map (decompress_info_ptr cinfo, int num_colors, JSAMPARRAY colormap)
{
register JSAMPROW color_map0 = cinfo->colormap[0];
register JSAMPROW color_map1 = cinfo->colormap[1];
register JSAMPROW color_map2 = cinfo->colormap[2];
UWORD i;
if (cinfo->quantize_colors) {
for (i = 0;
i < num_colors;
++i) {
r1[i] = GETJSAMPLE(color_map0[i]);
g1[i] = GETJSAMPLE(color_map1[i]);
b1[i] = GETJSAMPLE(color_map2[i]);
}
}
}
/*
* Finish up at the end of the file.
*/
METHODDEF void
output_term (decompress_info_ptr cinfo)
{
/* Do nothing */
}
/*
* The method selection routine for Memory format output.
* This should be called from d_ui_method_selection if Memory output is wanted.
*/
GLOBAL void
jselwmem (decompress_info_ptr cinfo)
{
cinfo->methods->output_init = output_init;
cinfo->methods->put_color_map = put_color_map;
cinfo->methods->put_pixel_rows = put_color_rows;
cinfo->methods->output_term = output_term;
}